Tool methods in jquery $. isFunction, $. isArray (), $. isWindow ()
In javascript's judgment on the variable type, we explained in jquery$.type()Implementation principle. Of course, in addition to providing$.typeIn addition to the tool methods,
This article official address: Http://www.xiabingbao.com/javascript/2015/07/04/javascript-typeIn JavaScript, we explain the principle of the implementation of jquery in the judgment of variable types $.type() . Of course, jquery offers several other
This article mainly introduces how to use jquery tools $. isFunction, $. isArray (), $. isWindow (). If you need it, you can refer to the variable type judgment in javascript. We have explained $ in jquery. type () implementation principle. Of
$. IsFunction, $. isArray (), $. isWindow (), jquery. isfunction
Address: http://www.xiabingbao.com/jquery/2015/07/25/jquery-judge-type
In javascript's judgment on the variable type, we explained in jquery$.type()Implementation principle. Of course,
In JavaScript, in the judgment of variable types, we explain the principle of $.type () implementation in jquery. Of course, jquery offers several other tools, in addition to the $.type tool approach: $.isfunction (), $.isarray (), $.iswindow (),
1. typeof operator. For Function, String, Number, and Undefined objects, there is no problem, but the objects for Array are useless:
Js Code
Copy codeThe Code is as follows: alert (typeof null); // "object"
Alert (typeof []); // "object"
2.
In our usual work, we often use how to tell if a variable is an array. Common methods are many, useful in the common frame, isarray. But the realization of this isarray is different.There are several common methods1, instanceoffunction isArray (obj)
1. typeof operator. For Function, String, Number, and Undefined objects, there is no problem, but the objects for Array are useless:Js CodeCopy codeThe Code is as follows:Alert (typeof null); // "object"Alert (typeof []); // "object" 2. instanceof
The IsArray function returns a Boolean value indicating whether a variable is an array.
IsArray functionReturns a Boolean value that indicates whether a variable is an array.GrammarIsArray (varname)The varname parameter can be any
IsArray functionReturns a Boolean value that indicates whether a variable is an array.GrammarIsArray (varname)The varname parameter can be any variable.DescriptionIf the variable is an array, the IsArray function returns TRUE, otherwise the function
1, typeof operator. There are no problems with functions, String, number, undefined objects of these types, but objects for array are useless:
JS Code
Copy Code code as follows:
Alert (typeof null); "Object"
Alert (typeof []);
IsArray Function
Returns a Boolean value to indicate whether a variable is an array.
IsArray (Varname)
VarnameThe parameter can be any variable.Description
If the variable is an array,IsArrayFunction returnTrueOtherwise, the function
1) typeof operatortypeof is a unary operator, and the return result is a string indicating the type of the operand. such as: "Number", "string", "Boolean", "Object", "function", "undefined" (can be used to determine whether a variable exists).
But
1) typeof Operator
Typeof is a unary operator. The returned result is a string indicating the number of operations. For example, "Number", "string", "Boolean", "object", "function", and "undefined" (used to determine whether a variable exists
1) typeof OperatorTypeof is a unary operator. The returned result is a string indicating the number of operations. For example, "number", "string", "boolean", "object", "function", and "undefined" (used to determine whether a variable exists
We know that operators for detecting object types in Javascript include typeof, instanceof, and constructor attributes of objects:
1)TypeofOperatorTypeof is a unary operator. The returned result is a string indicating the number of operations. For
1) typeof operator
typeof is a unary operator, and the return result is a string indicating the type of the operand. such as: "Number", "string", "Boolean", "Object", "function", "undefined" (can be used to determine whether a variable exists).
But
Today's project logic needs to pass the number of groups past. Then a generic method is invoked. But the parameter of this method is object. If you change the parameter type, the other module calls this method and there is a problem.
The final
Array.isarray ()Used to verify that arrays are not var a = [Console.log] (typeof a); // Object Console.log (Array.isarray (a)); // trueIt can be seen that typeof does not validate the array, although Array.isarray () can
Today just learning to pay the Treasure JS framework base.js. With a glance, the realization is this:
Copy Code code as follows:
if (value instanceof Array | |
(! (Value instanceof Object) &&
(Object.prototype.toString.call
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.